﻿using System;
using System.Collections.ObjectModel;
using AuchanScan.Datas;
using AuchanScan.Services;
using System.ComponentModel;

namespace AuchanScan.ViewModels
{
    public class PromoViewModel : INotifyPropertyChanged
    {
        public PromoViewModel()
        {
           
            Initialize();
        }
       

        public PromotionService PromotionService { get { return PromotionService.Current; } }
        private void Initialize()
        {
           

          
        }
        


       /* public Tract SelectedTract
        {
            get { return _SelectedTract; }
            set
            {
                if (_SelectedTract != value)
                {
                    _SelectedTract = value;
                    RaisePropertyChanged(() => SelectedTract);
                    NavigationServiceHelper.Instance.NavigateTo(new Uri(string.Format("/PromoOffresPage.xaml?tid={0}", _SelectedTract.Id), UriKind.RelativeOrAbsolute));
                }
            }
        }
        
        public Rayon SelectedRayon {
            get { return _SelectedRayon; }
            set
            {
                if (_SelectedRayon != value)
                {
                    _SelectedRayon = value;
                    RaisePropertyChanged(() => SelectedRayon);
                    NavigationServiceHelper.Instance.NavigateTo(new Uri(string.Format("/PromoRayonPage.xaml?rid={0}", _SelectedRayon.Id), UriKind.RelativeOrAbsolute));
                }
            }
        }

     
        /// <summary>
        /// Load all offres
        /// </summary>
        /// <param name="id"></param>
        public void LoadTractOffres(int id)
        {
            var offres = PromotionService.LoadTractOffres(id);
            if (offres != null && offres.Count > 0)
            {
                Offres.Clear();
                foreach (var o in offres)
                {
                    Offres.Add(o);
                    System.Threading.Thread.Sleep(20);
                }
            }
        }

        /// <summary>
        /// Load Rayons Offres
        /// </summary>
        /// <param name="id"></param>
        public void LoadRayonOffres(int id)
        {
            var offres = PromotionService.LoadRayonOffres(id);
            if (offres != null && offres.Count > 0)
            {
                Offres.Clear();
                foreach (var o in offres)
                {
                    Offres.Add(o);
                    System.Threading.Thread.Sleep(20);
                }
            }
        }

        */
        #region INotifyPropertyChanged Implementation

        public event PropertyChangedEventHandler PropertyChanged;
        private Tract _SelectedTract;
        private Rayon _SelectedRayon;

        protected void RaisePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

       /* protected void RaisePropertyChanged<T>(Expression<Func<T>> expression)
        {
            if (!(expression.Body is MemberExpression))
                return;

            MemberExpression memberExpression = (MemberExpression)expression.Body;
            string propertyName = memberExpression.Member.Name;
            RaisePropertyChanged(propertyName);
        }*/

        #endregion
    }
}
